﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Linq;
using UniMana.Data;
namespace UniMana.Data
{
    public static class Graduate_ExamSubjectData
    {
        public static IQueryable GetList(this  Table<Graduate_ExamSubject> tExamSubject,
                                                Table<Training_Subject> tSubject, 
                                                Table<Graduate_Exam> tExam, int iExamkey = -1)
        {
            var l = from examSubject in tExamSubject
                    from subject in tSubject
                    from exam in tExam

                    where examSubject.Training_SubjectKey == subject.Training_SubjectKey
                    where  examSubject.Graduate_ExamKey == exam.Graduate_ExamKey

                    orderby examSubject.Graduate_SubjectExamKey descending

                    select new
                    {
                        examSubject.Graduate_SubjectExamKey,
                        examKey = examSubject.Graduate_ExamKey,
                        examSubject.Training_Subject_ClassKey,
                        Exam = examSubject.Exam == null ? false : examSubject.Exam,
                        Thesis = examSubject.Thesis == null ? false : examSubject.Thesis,
                        Practice = examSubject.Practice == null ? false : examSubject.Practice,

                        IDExam = exam.ExamID,
                        exam.DateExam,

                        subject.Training_SubjectKey,
                        subjectID = subject.ID,
                        subjectName = subject.Name
                    };
            if (iExamkey != -1)
            {
                l = l.Where(p => p.examKey == iExamkey);
            }
            return l;
        }
    }
}
